package com.lhf.aicloud.utils;

import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author : lhf
 * @date : Created in 2024/07/27
 * @description: 统一返回结果
 */
@Data
public class ResponseEntity implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    // 状态码
    private int code;
    // 响应信息
    private String msg;
    // 响应数据
    private Object data;

    public ResponseEntity(){
        this.code = 200;
        this.msg = "success";
    }
    public static ResponseEntity success(Object data) {
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setCode(200);
        responseEntity.setMsg("success");
        responseEntity.setData(data);
        return responseEntity;
    }

    public static ResponseEntity error(int code, String msg) {
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setCode(code);
        responseEntity.setMsg(msg);
        return responseEntity;
    }

    public static ResponseEntity error(String msg) {
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setCode(500);
        responseEntity.setMsg(msg);
        return responseEntity;
    }
}
